/* Replication data, analyses, and figures for: "Leading Toward Equality: The 
	Effect of Women Mayors on Gender Equality in Local Bureaucracies." 2017. 
	Published at Politics, Groups, and Identities.
	
	Authors: Kendall Funk, Thiago Silva, and Maria Escobar-Lemmon

	Date: November, 2017 */

* Setting the directory
clear
capture cd "~/Downloads/Replication Files" 
set more off 

* Opening dataset 
use "FSE_Master.dta", clear

* Need to time set the data
xtset ibgecode year

********************************************************************************
* Replication of Table 1. 
* Do women mayors increase women's equality in the executive bureaucracy?
********************************************************************************

eststo clear
set more off

* (Model 1) % Women Bureaucrats
eststo: xtreg pctfempubadmin femalemayor_new pctfemcouncils_new left_new ///
right_new mayoreducation_new mayorage_new logpop loggdppercap patronage ///
bureaucracysizepop yearinterm previousterm lag_pctfempubadmin

* (Model 2) Average Women Salary
eststo: xtreg avgfemsalnommpa_adj femalemayor_new pctfemcouncils_new left_new ///
right_new mayoreducation_new mayorage_new logpop loggdppercap patronage ///
bureaucracysizepop previousterm yearinterm lag_avgfemsalnommpa

* (Model 3) Wage Gap
eststo: xtreg wagegapsalmpa_adj femalemayor_new pctfemcouncils_new left_new ///
right_new mayoreducation_new mayorage_new logpop loggdppercap patronage ///
bureaucracysizepop previousterm yearinterm lag_wagegapsalmpa

* Regression Table in Latex:
esttab using regression.tex, label se r2 replace 

********************************************************************************
* Replication of Figures using DynSim package

* Package's authors: Christopher Gandrud, Laron K. Williams, and Guy D. Whitten
* Package's URL: http://cran.r-project.org/package=dynsim
********************************************************************************

********************************************************************************
* Replication of Figure 1. Dynamic simulations of the effects of mayor’s gender 
* on percent women in the municipal executive bureaucracy.
********************************************************************************

estsimp reg pctfempubadmin femalemayor_new pctfemcouncils_new left_new right_new mayoreducation_new mayorage_new logpop loggdppercap patronage bureaucracysizepop previousterm yearinterm lag_pctfempubadmin, genname(g)
sum lag_pctfempubadmin if year==2012 // 62.73628

* 1.1 M-M-M
dynsim, ldv(lag_pctfempubadmin) ///
scen1(lag_pctfempubadmin 62.73628 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim.dta") shock(femalemayor_new) shock_num(0 0 0 0 0 0 0 0 0 0 0 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("% Women Exe. Bur.", size(3)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "T5" 5 "T6" 6 "T7" 7 "T8" 8 "T9" 9 "T10" 10 "T11" 11 "T12", labsize(2.5) angle(45)) ///
title("M-M-M") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(61(.5)63, labsize(2.5)) name(g1_1, replace)
graph save "g1_1.gph", replace
restore 

* 1.2 M-M-W
dynsim, ldv(lag_pctfempubadmin) ///
scen1(lag_pctfempubadmin 62.73628 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim.dta") shock(femalemayor_new) shock_num(0 0 0 0 0 0 0 1 1 1 1 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("% Women Exe. Bur.", size(0)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "T5" 5 "T6" 6 "T7" 7 "T8" 8 "{bf:T9}" 9 "{bf:T10}" 10 "{bf:T11}" 11 "{bf:T12}", labsize(2.5) angle(45)) ///
title("M-M-{bf:W}") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(61(.5)63, labsize(0)) name(g1_2, replace)
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g1_2.gph", replace
restore 

* 1.3 M-W-M
dynsim, ldv(lag_pctfempubadmin) ///
scen1(lag_pctfempubadmin 62.73628 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim.dta") shock(femalemayor_new) shock_num(0 0 0 1 1 1 1 0 0 0 0 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("% Women Exe. Bur.", size(3)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "{bf:T5}" 5 "{bf:T6}" 6 "{bf:T7}" 7 "{bf:T8}" 8 "T9" 9 "T10" 10 "T11" 11 "T12", labsize(2.5) angle(45)) ///
title("M-{bf:W}-M") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(61(.5)63, labsize(2.5)) name(g1_3, replace)
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g1_3.gph", replace
restore 

* 1.4 M-W-W
dynsim, ldv(lag_pctfempubadmin) ///
scen1(lag_pctfempubadmin 62.73628 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim.dta") shock(femalemayor_new) shock_num(0 0 0 1 1 1 1 1 1 1 1 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("% Women Exe. Bur.", size(0)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "{bf:T5}" 5 "{bf:T6}" 6 "{bf:T7}" 7 "{bf:T8}" 8 "{bf:T9}" 9 "{bf:T10}" 10 "{bf:T11}" 11 "{bf:T12}", labsize(2.5) angle(45)) ///
title("M-{bf:W}-{bf:W}") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(61(.5)63, labsize(0)) name(g1_4, replace)
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g1_4.gph", replace
restore 

* Combining graphs
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
grc1leg "g1_1.gph" "g1_2.gph" "g1_3.gph" ///
 "g1_4.gph", imargins(tiny) position(6) name(pctfemM, replace) scheme(s2mono)
graph export "Figure_1.pdf", name(pctfemM) replace

********************************************************************************
* Replication of Figure 2. Dynamic simulations of the effects of mayor’s gender 
* on the average real wages of women bureaucrats.
********************************************************************************

estsimp reg avgfemsalnommpa_adj femalemayor_new pctfemcouncils_new left_new right_new mayoreducation_new mayorage_new logpop loggdppercap patronage bureaucracysizepop previousterm yearinterm lag_avgfemsalnommpa, genname(a)
sum lag_avgfemsalnommpa if year==2012 // 1036.773

* 2.1 M-M-M 
dynsim, ldv(lag_avgfemsalnommpa) ///
scen1(lag_avgfemsalnommpa 1036.773 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim.dta") shock(femalemayor_new) shock_num(0 0 0 0 0 0 0 0 0 0 0 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("Avg. Women Salary", size(3)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "T5" 5 "T6" 6 "T7" 7 "T8" 8 "T9" 9 "T10" 10 "T11" 11 "T12", labsize(2.5) angle(45)) ///
title("M-M-M") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(1025(25)1125, labsize(2.5)) name(g2_1, replace)
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g2_1.gph", replace
restore 

* 2.2 M-M-W 
dynsim, ldv(lag_avgfemsalnommpa) ///
scen1(lag_avgfemsalnommpa 1036.773 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim") shock(femalemayor_new) shock_num(0 0 0 0 0 0 0 1 1 1 1 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("", size(3)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "T5" 5 "T6" 6 "T7" 7 "T8" 8 "{bf:T9}" 9 "{bf:T10}" 10 "{bf:T11}" 11 "{bf:T12}", labsize(2.5) angle(45)) ///
title("M-M-{bf:W}") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(1025(25)1125, labsize(0)) name(g2_2, replace)
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g2_2.gph", replace
restore 

* 2.3 M-W-M
dynsim, ldv(lag_avgfemsalnommpa) ///
scen1(lag_avgfemsalnommpa 1036.773 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim") shock(femalemayor_new) shock_num(0 0 0 1 1 1 1 0 0 0 0 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("Avg. Women Salary", size(3)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "{bf:T5}" 5 "{bf:T6}" 6 "{bf:T7}" 7 "{bf:T8}" 8 "T9" 9 "T10" 10 "T11" 11 "T12", labsize(2.5) angle(45)) ///
title("M-{bf:W}-M") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(1025(25)1125, labsize(2.5)) name(g2_3, replace)
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g2_3.gph", replace
restore 

* 2.4 M-W-W
dynsim, ldv(lag_avgfemsalnommpa) ///
scen1(lag_avgfemsalnommpa 1036.773 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("salarysim") shock(femalemayor_new) shock_num(0 0 0 1 1 1 1 1 1 1 1 0)
preserve 
use "salarysim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("Avg. Women Salary", size(0)) xtitle("") ///
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "{bf:T5}" 5 "{bf:T6}" 6 "{bf:T7}" 7 "{bf:T8}" 8 "{bf:T9}" 9 "{bf:T10}" 10 "{bf:T11}" 11 "{bf:T12}", labsize(2.5) angle(45)) ///
title("M-{bf:W}-{bf:W}") scheme(s2mono) legend(label (1 "95% confidence intervals")) legend(off) ylabel(1025(25)1125, labsize(0)) name(g2_4, replace)
graph save "g2_4.gph", replace
restore 

* Combining graphs
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
grc1leg "g2_1.gph" "g2_2.gph" "g2_3.gph" ///
 "g2_4.gph", imargins(tiny) position(6) name(salaryM, replace) scheme(s2mono)
graph export "Figure_2.pdf", name(salaryM) replace

**************************************************************
* Model 3: Status Gap 
**************************************************************
estsimp reg wagegapsalmpa_adj femalemayor_new pctfemcouncils_new left_new right_new mayoreducation_new mayorage_new logpop loggdppercap patronage bureaucracysizepop previousterm yearinterm lag_wagegapsalmpa, genname(c) 
sum lag_wagegapsalmpa if year==2012 // 149.0034

* 3.1 M-M-M
dynsim, ldv(lag_wagegapsalmpa) ///
scen1(lag_wagegapsalmpa 149.0034 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("gapsim") shock(femalemayor_new) shock_num(0 0 0 0 0 0 0 0 0 0 0 0)
preserve 
use "gapsim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("Avg. Wage Gap", size(3)) ///
legend(label (1 "95% Confidence Intervals")) xtitle("") name(g3_1, replace) /// 
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "T5" 5 "T6" 6 "T7" 7 "T8" 8 "T9" 9 "T10" 10 "T11" 11 "T12", labsize(2.5) angle(45)) ///
title("M-M-M", size(4)) scheme(s2mono) legend(off) ylabel(135(10)175, labsize(2.5))
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g3_1.gph", replace
restore 

* 3.2 M-M-W
dynsim, ldv(lag_wagegapsalmpa) ///
scen1(lag_wagegapsalmpa 149.0034 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("gapsim") shock(femalemayor_new) shock_num(0 0 0 0 0 0 0 1 1 1 1 0)
preserve 
use "gapsim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("Avg. Wage Gap", size(0)) ///
legend(label (1 "95% Confidence Intervals")) xtitle("") name(g3_2, replace) /// 
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "T5" 5 "T6" 6 "T7" 7 "T8" 8 "{bf:T9}" 9 "{bf:T10}" 10 "{bf:T11}" 11 "{bf:T12}", labsize(2.5) angle(45)) ///
title("M-M-{bf:W}", size(4)) scheme(s2mono) legend(off) ylabel(135(10)175, labsize(0))
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g3_2.gph", replace
restore 

* 3.3 M-W-M
dynsim, ldv(lag_wagegapsalmpa) ///
scen1(lag_wagegapsalmpa 149.0034 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("gapsim") shock(femalemayor_new) shock_num(0 0 0 1 1 1 1 0 0 0 0 0)
preserve 
use "gapsim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("Avg. Wage Gap", size(3)) ///
legend(label (1 "95% Confidence Intervals")) xtitle("") name(g3_3, replace) /// 
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "{bf:T5}" 5 "{bf:T6}" 6 "{bf:T7}" 7 "{bf:T8}" 8 "T9" 9 "T10" 10 "T11" 11 "T12", labsize(2.5) angle(45)) ///
title("M-{bf:W}-M", size(4)) scheme(s2mono) legend(off) ylabel(135(10)175, labsize(2.5))
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g3_3.gph", replace
restore 

* 3.4 M-W-W
dynsim, ldv(lag_wagegapsalmpa) ///
scen1(lag_wagegapsalmpa 149.0034 femalemayor_new 0 pctfemcouncils_new mean left_new 1 right_new 0 mayoreducation_new mean logpop mean loggdppercap mean patronage mean bureaucracysizepop mean mayorage_new mean previousterm 0 yearinterm mean) ///
sig(95) n(11) saving("gapsim") shock(femalemayor_new) shock_num(0 0 0 1 1 1 1 1 1 1 1 0)
preserve 
use "gapsim.dta", clear
twoway rcapsym lower_1 upper_1 t, msymbol(O) ytitle("Avg. Wage Gap", size(0)) ///
legend(label (1 "95% Confidence Intervals")) xtitle("") name(g3_4, replace) /// 
xlabel(0 "T1" 1 "T2" 2 "T3" 3 "T4" 4 "{bf:T5}" 5 "{bf:T6}" 6 "{bf:T7}" 7 "{bf:T8}" 8 "{bf:T9}" 9 "{bf:T10}" 10 "{bf:T11}" 11 "{bf:T12}", labsize(2.5) angle(45)) ///
title("M-{bf:W}-{bf:W}", size(4)) scheme(s2mono) legend(off) ylabel(135(10)175, labsize(0))
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
graph save "g3_4.gph", replace
restore 

* Combining graphs
local address ~/Dropbox/Leading Ladies Project/PGI/2. Revision 1/Models and Figures/Figures
grc1leg "g3_1.gph" "g3_2.gph" "g3_3.gph" ///
 "g3_4.gph", imargins(tiny) position(6) name(gapshockM, replace) scheme(s2mono)
graph export "Figure_3.pdf", name(gapshockM) replace

********************************************************************************
* Replication of Appendix 1. 
********************************************************************************

* Replication of Table A1. Variable names and summary statistics.
sutex pctfempubadmin avgfemsalnommpa_adj wagegapsalmpa_adj femalemayor_new pctfemcouncils_new ///
left_new right_new mayoreducation_new mayorage_new population gdppc patronage ///
bureaucracysizepop yearinterm previousterm, lab replace ///
file(Table_A1.tex) title("Variable names and summary statistics") minmax 


********************************************************************************
* Replication of Appendix 2. 
********************************************************************************

* Replication of Figure A1. Time series for the dependent and main independent variables.
* See R script: "FSE_Replication_Figure_A1.R"
